home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12326 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: mother.usf.edu!news
  2. From: yatesc@csee.usf.edu (Randy Yates)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: what getline returns? Nobody can explain this!!
  5. Date: 19 Mar 1996 14:58:17 GMT
  6. Organization: University of South Florida
  7. Distribution: na
  8. Message-ID: <4imi29$cf3@mother.usf.edu>
  9. References: <4ifbk8$6nf@bcarh8ab.bnr.ca>
  10. NNTP-Posting-Host: ppp129.cfr.usf.edu
  11. Mime-Version: 1.0
  12. X-Newsreader: WinVN 0.93.14
  13.  
  14. In article <4ifbk8$6nf@bcarh8ab.bnr.ca>, liyu@bnr.ca says...
  15. >
  16. >getline member fuction in ifstream is supposed to return the
  17. >receiving object (that is, ostream&). 
  18. >
  19. >However, many books contain the code samples like:
  20. >
  21. >ifstream in("tmp.txt");
  22. >while (in.getline(buffer,sizeof(buffer))) { ...  }
  23. >
  24. >This loop quits only if in.getline returns 0 or NUll;
  25. >                ^^^^^^^
  26. >
  27. >but an ostream object is neither 0 nor NULL;
  28. >the result is an object, not integer or pointer.
  29. >
  30. >So how can this loop quit?
  31. >
  32. >It works; but no one I know can explain this!!!!
  33. >Thanks for your help.
  34.  
  35. It may work but I never use it that way. This is my
  36. preferred method (used here to get lines from a UNIX
  37. type file and convert them to DOS type):
  38.  
  39.   infile.getline(line, MAX_LINE_LENGTH, 0x0A);
  40.   while (!infile.eof())
  41.   {
  42.     index=strlen(line);
  43.     line[index]=0x0D;
  44.     line[index+1]=0x0A;
  45.     line[index+2]=0;
  46.     outfile << line;
  47.     infile.getline(line, MAX_LINE_LENGTH, 0x0A);
  48.   }
  49.  
  50. -- 
  51. % Randy Yates                  % "...the answer lies within your soul
  52. % EE/Mathematics Student       %       'cause no one knows which side 
  53. % University of South Florida  %                   the coin will fall."
  54. % <yatesc@csee.usf.edu>        %  'Big Wheels', *Out of the Blue*, ELO   
  55.  
  56.